﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using thinger.MTHModels;

namespace thinger.MTHDAL
{
    public class ActualDataServer
    {
        public DataTable ActualDataByTime(string start, string end)
        {
            try
            {
                string sql = "Select InsertTime,Station1Temp,Station1Humidity,Station2Temp,Station2Humidity,Station3Temp,Station3Humidity,Station4Temp,Station4Humidity,Station5Temp,Station5Humidity,Station6Temp,Station6Humidity";

                sql += "from actual_data Where InsertTime between @start and @end";

                List<MySqlParameter> mySqlParameters = new MySqlParameter[]
                {
                new MySqlParameter("@start", start),
                new MySqlParameter("@end", end)

                }.ToList();

                DataSet dataSet = thinger.MTHHelper.MySqlHelper.GetDataSet(sql, mySqlParameters.ToArray());

                if (dataSet != null && dataSet.Tables.Count > 0)
                {
                    DataTable dataTable = dataSet.Tables[0];
                }
                return null;
            }
            catch (Exception)
            {

                return null;
            }


        }

        public int AddActual(ActualData actualData)
        {
            try
            {
                string sql = "Insert into actual_data(InsertTime,Station1Temp,Station1Humidity,Station2Temp,Station2Humidity,Station3Temp,Station3Humidity,Station4Temp,Station4Humidity,Station5Temp,Station5Humidity,Station6Temp,Station6Humidity)";

                sql += "values(@InsertTime,@Station1Temp,@Station1Humidity,@Station2Temp,@Station2Humidity,@Station3Temp,@Station3Humidity,@Station4Temp,@Station4Humidity,@Station5Temp,@Station5Humidity,@Station6Temp,@Station6Humidity)";

                List<MySqlParameter> mySqlParameters = new MySqlParameter[]
                {
                new MySqlParameter("@InsertTime", actualData.InsertTime),
                new MySqlParameter("@Station1Temp", actualData.Station1Temp),
                new MySqlParameter("@Station1Humidity", actualData.Station1Humidity),
                new MySqlParameter("@Station2Temp", actualData.Station2Temp),
                new MySqlParameter("@Station2Humidity", actualData.Station2Humidity),
                new MySqlParameter("@Station3Temp", actualData.Station3Temp),
                new MySqlParameter("@Station3Humidity", actualData.Station3Humidity),
                new MySqlParameter("@Station4Temp", actualData.Station4Temp),
                new MySqlParameter("@Station4Humidity", actualData.Station4Humidity),
                new MySqlParameter("@Station5Temp", actualData.Station5Temp),
                new MySqlParameter("@Station5Humidity", actualData.Station5Humidity),
                new MySqlParameter("@Station6Temp", actualData.Station6Temp),
                new MySqlParameter("@Station6Humidity", actualData.Station6Humidity),


                }.ToList();

                int result = thinger.MTHHelper.MySqlHelper.ExecuteSql(sql, mySqlParameters.ToArray());

                return result;
            }
            catch (Exception)
            {

                return -1;
            }
            

        }

        private static int AddActual(string sql, List<MySqlParameter> mySqlParameters)
        {
            throw new NotImplementedException();
        }
    }
}
